<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>rooms.jmpup.com</title>
    <meta name="author" content="Peter Kishalov" />
    <meta name="description" content="" />
    <meta name="keywords" content="iq IQ logic puzzle online entertainment mind cracking smullyan" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8; no-cache" />
    <link rel="stylesheet" type="text/css" href="styles.css" />
  </head>
  <body>

<form name="choice" action="http://rooms.jmpup.com/check.php" method="post">
<table cellspacing="0px" cellpadding="0px">
<tr class="title"><td>rooms.JMPUP.com</td></tr>

<?php
$seed = (int)$_GET['seed'];
$level = (int)$_GET['level'];
if( $level < 0 )
$level = 0;
else if( $level > 100 )
$level = 100;
$rcnt = (int)$_GET['rcnt'];
$rank = (int)$_GET['rank'];

echo '<input type="hidden" name="seed" value="'.$seed.'"/>';
echo '<input type="hidden" name="level" value="'.$level.'"/>';
echo '<input type="hidden" name="rcnt" value="'.$rcnt.'"/>';
echo '<input type="hidden" name="rank" value="'.$rank.'"/>';
       
$output = shell_exec( "cd /home/petkish/executables && ./doors $seed $level" );
$subjects = explode( "&\n", $output );
$doors = explode( '#', $subjects[0] );
$dcount = sizeof($doors) - 1;
if( sizeof($subjects) > 1 ){
$people = explode( '#', $subjects[1] );
$pcount = sizeof($people) - 1;
}else $pcount = 0;

echo '<tr class="content"><td><img src="images/left.png"/><br/><b>There are '.$dcount.' doors';
if( $pcount == 1 ) echo ' and 1 person'; else if( $pcount > 1 ) echo ' and '.$pcount.' persons'; 
echo ' in this room.</b></td></tr>';
       
for( $i = 1; $i < sizeof($doors); ++$i ){
$dlines[$i] = explode( "\n", $doors[$i] );
$door[$i] = explode( ';', $dlines[$i][0] );
}

for( $i = 1; $i < sizeof($people); ++$i ){
$plines[$i] = explode( "\n", $people[$i] );
$person[$i] = explode( ';', $plines[$i][0] );
}

echo '<tr class="content"><td><table><tr><td><table><tr style="text-align:center">';
for( $i = 1; $i < sizeof($doors); ++$i ){
echo '<td width="36px"><input type="radio" value="'.$i.'" id="door'.$i.'" name="doors"';
if( $i == 1 ) echo ' checked';
echo '/></td>';
}
echo '<td></td></tr><tr>';
$dropped = false;
for( $i = 1; $i < sizeof($doors); ++$i ){
$color = $door[$i][1];
echo '<td><label for="door'.$i.'">';
if( $door[$i][4] ){
echo '<img src="images/'.$color.'door.png" title="Door '.$i.':';
for( $l = 1; $l < sizeof($dlines[$i]); $l += 2 )
echo ' '.$dlines[$i][$l];
}else{
$dropped = true;
echo '<img src="images/'.$color.'door_nosign.png" title="Door '.$i.': No sign on this door!';
}
echo '"/></label></td>';
}
echo '<td></td><td></td></tr></table></td></tr>';

$backwards = false;
if( $dropped ){
echo '<tr><td><table><tr>';
$backwards = rand() % 2;
if( $backwards ){
for( $i = sizeof($doors) - 1; $i > 0 ; --$i ){
if( !$door[$i][4] ){
echo '<td width="12px"><img src="images/sign.png" title="';
for( $l = 1; $l < sizeof($dlines[$i]); $l += 2 ) echo ' '.$dlines[$i][$l];
echo '"/></td>';
}
}
}else{
for( $i = 1; $i < sizeof($doors); ++$i ){
if( !$door[$i][4] ){
echo '<td width="12px"><img src="images/sign.png" title="';
for( $l = 1; $l < sizeof($dlines[$i]); $l += 2 ) echo ' '.$dlines[$i][$l];
echo '"/></td>';
}
}
}
echo '<td></td></tr></table></td></tr>';
}

if($pcount > 0){
echo '<tr><td><table><tr style="text-align:center">';
for( $i = 1; $i < sizeof($people); ++$i ){
echo '<td width="64px">';
if( $person[$i][4] == '1' ) echo '<select name="p'.$i.'"><option value="friend">friend</option><option value="enemy">enemy</option></select>';
echo '</td>';
}
echo '<td></td></tr><tr>';
for( $i = 1; $i < sizeof($people); ++$i ){
$type = ($person[$i][4] == '1') ? 'incognito' : $person[$i][1];
$color = $person[$i][2];
$fat = ($person[$i][5] == '1') ? 'fat' : 'slim';
echo '<td><img src="images/person_'.$color.'_'.$type.'_'.$fat.'.png" title="';
for( $l = 1; $l < sizeof($plines[$i]); $l += 2 ) echo ' '.$plines[$i][$l];
echo '"/></td>';
}
echo '<td></td></tr></table></td></tr>';
}

echo '</table></td></tr>';

for( $i = 1; $i < sizeof($doors); ++$i ){
if( $door[$i][4] ){
$color = $door[$i][1];
echo '<tr class="content"><td><b>Door '.$i.'. Sign reads:</b><br/>';
for( $l = 1; $l < sizeof($dlines[$i]); $l += 2 ) echo '<i title="'.$dlines[$i][$l+1].'">'.$dlines[$i][$l].'</i><br/>';
echo '</td></tr>';
}
}

if( $dropped ){
if( $backwards ){
for( $i = sizeof( $doors ) - 1; $i > 0 ; --$i ){
if( !$door[$i][4] ){
echo '<tr class="content"><td><b>Sign on the floor:</b><br/>';
for( $l = 1; $l < sizeof($dlines[$i]); $l += 2 ) echo '<i title="'.$dlines[$i][$l+1].'">'.$dlines[$i][$l].'</i><br/>';
echo '</td></tr>';
}
}
}else{
for( $i = 1; $i < sizeof( $doors ); ++$i ){
if( !$door[$i][4] ){
echo '<tr class="content"><td><b>Sign on the floor:</b><br/>';
for( $l = 1; $l < sizeof($dlines[$i]); $l += 2 ) echo '<i title="'.$dlines[$i][$l+1].'">'.$dlines[$i][$l].'</i><br/>';
echo '</td></tr>';
}
}
}
}

for( $i = 1; $i < sizeof($people); ++$i ){
echo '<tr class="content"><td><b>Person '.$i.':</b><br/>';
for( $l = 1; $l < sizeof($plines[$i]); $l += 2 ) echo '<i title="'.$plines[$i][$l+1].'">'.$plines[$i][$l].'</i><br/>';
echo '</td></tr>';
}

echo '<tr class="content"><td><input type="submit" value="GO!"/></td></tr>';

?>

<tr class="packshot"><td>
Copyright &copy; Peter Kishalov, 2010.
</td></tr>

</table>
</form>

</body>
</html>
